package com.cloudwise.gproject.service;

import com.cloudwise.gproject.entity.Log;
import com.cloudwise.gproject.dao.LogDao;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (Log)表服务实现类
 *
 * @author makejava
 * @since 2021-03-22 13:28:07
 */
@Service("logService")
public class LogServiceImpl implements LogService {
    @Resource
    private LogDao logDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Log queryById(Integer id) {
        return this.logDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Log> queryAllByLimit(int offset, int limit) {
        return this.logDao.queryAllByLimit(offset, limit);
    }

    @Override
    public PageInfo queryAll(Integer page, Integer limit, Log log) {
        //设值查询查询
        PageHelper.startPage(page,limit);
        PageInfo PageInfo = new PageInfo(logDao.queryAll(log));
        return PageInfo;
    }

    /**
     * 新增数据
     *
     * @param log 实例对象
     * @return 实例对象
     */
    @Override
    public Log insert(Log log) {
        this.logDao.insert(log);
        return log;
    }

    /**
     * 修改数据
     *
     * @param log 实例对象
     * @return 实例对象
     */
    @Override
    public Log update(Log log) {
        this.logDao.update(log);
        return this.queryById(log.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.logDao.deleteById(id) > 0;
    }

    /**
     * @create by: 卫子健
     * @description: 通过多个id删除多个数据?
     * @create time: 2021/3/19 23:13
     */
    @Override
    public int deleteIds(String deleteIds) {
        return 0;
    }

    @Override
    public List<Map> queryShowChartData(int year, int month) {
        return logDao.queryShowChartData(year, month);
    }

    @Override
    public List<String> queryYear() {
        return logDao.queryYear();
    }

}
